home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Dr. Windows 3
/
dr win3.zip
/
dr win3
/
UTILITY1
/
HK10.ZIP
/
HKSRC.ZIP
/
HK.C
next >
Wrap
C/C++ Source or Header
|
1993-07-12
|
35KB
|
1,064 lines
//===========================================================
// HK - A Hotkey program for Windows.
// Copyright (C) 1993 Douglas Boling
//
// Revision History:
//
// 1.0 Initial Release
//
//===========================================================
// Returns no. of elements
#define dim(x) (sizeof(x) / sizeof(x[0]))
#define MAXFNAMELEN 128
#define MAXCMDLINELEN 256
#define MAXKEYNAMELEN 40
#define MAXHOTKEYS 64
#define ID_TIMER 1
//
// Undocumented things
//
#define WM_SETHOTKEY 0x32
#define WM_GETHOTKEY 0x33
//
// Custom messages
//
#define MYMSG_HKWINRIP WM_USER+10
#define MYMSG_HKWINERR WM_USER+11
#define MYMSG_ENABLEHK WM_USER+1
//-----------------------------------------------------------
// Include files
//-----------------------------------------------------------
#include "windows.h"
#include "commdlg.h"
#include "stdlib.h"
#include "string.h"
#include "HK.h"
//-----------------------------------------------------------
// Global data
//-----------------------------------------------------------
// Message dispatch table for MainWindowProc
struct decodeUINT MainMessages[] = {
WM_CREATE, DoCreateMain,
WM_COMMAND, DoCommandMain,
WM_TIMER, DoTimerMain,
WM_SIZE, DoSizeMain,
WM_CLOSE, DoCloseMain,
WM_DESTROY, DoDestroyMain,
MYMSG_HKWINRIP, DoHKWinRIPMain,
MYMSG_HKWINERR, DoHKWinErrMain,
};
// Command Message dispatch for MainWindowProc
struct decodeCMD MainMenuItems[] = {
IDD_KEYLIST, DoMainCtlKeyList,
IDD_ADD, DoMainCtlAdd,
IDD_DEL, DoMainCtlDel,
IDD_EDIT, DoMainCtlEdit,
IDD_ABOUT, DoMainCtlAbout,
IDD_EXIT, DoMainCtlExit,
IDOK, DoMainCtlExit,
IDCANCEL, DoMainCtlExit,
};
HANDLE hInst;
HWND hMain;
UINT wVersion = 10;
INT sTimerFreq;
char szAppName[] = "WinHK"; // Application name
char szIconName[] = "WinHKIcon"; // Icon name
char szProfileName[] = "HK.ini"; // INI file name
char szHKWinClass[] = "HKChildWin"; // Child Window Class name
// Edit box subclass vars
FARPROC lpfnEditSCProc, lpfnOldEditWndProc;
// Hotkey array vars
INT sNumHKs = 0;
INT sNumRunning = 0;
PHKENTRY phkArray;
// Return values from Add dialog
char szNewCL[MAXCMDLINELEN];
UINT wAddKey;
//============================================================
// WinMain -- entry point for this application from Windows.
//============================================================
INT APIENTRY WinMain(HANDLE hInstance, HANDLE hPrevInstance,
LPSTR lpCmdLine, INT nCmdShow) {
MSG msg;
INT rc;
hInst = hInstance;
// Only allow one instance of HK at a time
if(hPrevInstance) return 1;
if((rc = InitApp(hInstance)) != 0)
return rc;
// Initialize this instance
if((rc = InitInstance(hInstance, lpCmdLine, nCmdShow)) != 0)
return rc;
//
// Application message loop
//
while (GetMessage (&msg, NULL, 0, 0)) {
if (!IsDialogMessage (hMain, &msg)) {
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
// Instance cleanup
return TermInstance(hInstance, msg.wParam);
}
//-----------------------------------------------------------
// InitApp - Global initialization code for this application.
//-----------------------------------------------------------
INT InitApp(HANDLE hInstance) {
WNDCLASS wc;
//
// Register App Main Window class
//
wc.style = 0; // Window style
wc.lpfnWndProc = MainWndProc; // Callback function
wc.cbClsExtra = 0; // Extra class data
wc.cbWndExtra = DLGWINDOWEXTRA; // Extra window data
wc.hInstance = hInstance; // Owner handle
wc.hIcon = LoadIcon(hInst, szIconName); // Application icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Default cursor
wc.hbrBackground = GetStockObject(LTGRAY_BRUSH); // Background color
wc.lpszMenuName = NULL; // Menu name
wc.lpszClassName = szAppName; // Window class name
if (RegisterClass(&wc) == 0)
return 1;
//
// Register App Child Window class
//
wc.style = 0; // Window style
wc.lpfnWndProc = HKChildWndProc; // Callback function
wc.cbClsExtra = 0; // Extra class data
wc.cbWndExtra = sizeof (DWORD); // Extra window data
wc.hInstance = hInstance; // Owner handle
wc.hIcon = NULL; // Application icon
wc.hCursor = LoadCursor(NULL, IDC_ARROW); // Default cursor
wc.hbrBackground = GetStockObject(LTGRAY_BRUSH); // Background color
wc.lpszMenuName = NULL; // Menu name
wc.lpszClassName = szHKWinClass; // Window class name
if (RegisterClass(&wc) == 0)
return 2;
return 0;
}
//-----------------------------------------------------------
// InitInstance - Instance initialization code for this app.
//-----------------------------------------------------------
INT InitInstance(HANDLE hInstance, LPSTR lpCmdLine, INT nCmdShow) {
int i,j;
PHKENTRY phkPtr;
char szTemp[MAXCMDLINELEN+12];
char *pszCmd;
phkArray = (PHKENTRY) LocalAlloc (LPTR, sizeof (HKENTRY) * MAXHOTKEYS);
if (phkArray == 0)
return 11;
sTimerFreq = GetPrivateProfileInt (szAppName, PRO_TIMERFREQ,
1000, szProfileName);
//
// Read hot key information from the INI file
//
j = GetPrivateProfileInt (szAppName, PRO_HKCNT, 0, szProfileName);
sNumHKs = 0;
phkPtr = phkArray;
for (i = 0; i < j; i++) {
itoa (i, szTemp, 10);
GetPrivateProfileString (PRO_HKLST, szTemp, "0,", szTemp, sizeof (szTemp),
szProfileName);
pszCmd = strchr (szTemp,',');
if (pszCmd != 0) {
*pszCmd++ = '\0';
phkPtr->wKey = atoi (szTemp);
strcpy (phkPtr->szCmdLine, pszCmd);
phkPtr++;
sNumHKs++;
}
}
i = GetPrivateProfileInt (szAppName, PRO_XPOS, 100,
szProfileName);
j = GetPrivateProfileInt (szAppName, PRO_YPOS, 100,
szProfileName);
// Create main window
hMain = CreateDialog (hInstance, szAppName, 0, NULL);
if(!hMain) return 0x10;
SetWindowPos (hMain, NULL, i, j, 0, 0, SWP_NOSIZE);
ShowWindow(hMain, nCmdShow | SW_SHOW);
UpdateWindow(hMain); // force WM_PAINT message
return 0; // return success flag
}
//------------------------------------------------------------
// TermInstance - Instance termination code for this app.
//------------------------------------------------------------
INT TermInstance(HANDLE hinstance, int sDefRC) {
return sDefRC;
}
//============================================================
// Message handling procedures for MainWindow
//============================================================
//------------------------------------------------------------
// MainWndProc - Callback function for application window
//------------------------------------------------------------
LONG CALLBACK MainWndProc(HWND hWnd, UINT wMsg, UINT wParam,
LONG lParam) {
INT i;
//
// Search message list to see if we need to handle this
// message. If in list, call procedure.
//
for(i = 0; i < dim(MainMessages); i++) {
if(wMsg == MainMessages[i].Code)
return (*MainMessages[i].Fxn)(hWnd, wMsg, wParam, lParam);
}
return DefDlgProc(hWnd, wMsg, wParam, lParam);
}
//------------------------------------------------------------
// DoCreateMain - process WM_CREATE message for frame window.
//------------------------------------------------------------
LONG DoCreateMain (HWND hWnd, UINT wMsg, UINT wParam, LONG lParam) {
INT i;
PHKENTRY phkPtr;
phkPtr = phkArray;
for (i = 0; i < sNumHKs; i++) {
CreateHKWindow (hWnd, phkPtr);
phkPtr++;
}
SetActiveWindow (hWnd);
return 0;
}
//------------------------------------------------------------
// DoSizeMain - process WM_SIZE message for frame window.
//------------------------------------------------------------
LONG DoSizeMain (HWND hWnd, UINT wMsg, UINT wParam,